import sys

if __name__ == "__main__":
    cons = []
    is_tour_num = False
    if sys.argv[2] == 'MDVRP':
        cons.append('vehicleCap')
        cons.append('duration')
        is_tour_num = True
    elif sys.argv[2] == 'MDOVRP':
        cons.append('vehicleCap')
    elif sys.argv[2] == 'LRP':
        cons.append('vehicleCap')
        cons.append('depotCap')
    elif sys.argv[2] == 'MDGVRP' or sys.argv[2] == 'GVRP':
        cons.append('range')
        cons.append('duration')
    else:
        print("unsupported problem type "+sys.argv[2])
        exit(1)

    with open(sys.argv[1]+'/'+"Constraints.h", 'w') as f:
        constraintsEnum = '\nenum Constraint{\n\t'
        constraintsArray = 'const Constraint constraints[' + str(len(cons))+'] = {'
        load_cons_num = 0
        time_cons_num = 0
        range_cons_num = 0

        content = ''
        loadRelatedCons = ''
        timeRelatedCons = ''
        rangeRelatedCons = ''

        if is_tour_num:
            content += '#define Cons_tourNum\n'

        for con in cons:
            constraintsEnum += con + ', '
            constraintsArray += 'Constraint::'+con+', '
            content += '#define Cons_'+con+'\n'
            if con == 'vehicleCap':
                load_cons_num += 1
                loadRelatedCons += 'vehicleCap, '
            elif con == 'duration':
                time_cons_num += 1
                timeRelatedCons += 'duration, '
            elif con == 'depotCap':
                load_cons_num += 1
                loadRelatedCons += 'depotCap, '
            elif con == 'range':
                range_cons_num += 1
                rangeRelatedCons += 'range, '
            elif con == 'tourLength':
                range_cons_num += 1
                rangeRelatedCons += 'tourLength, '
            else:
                print("wrong constraint types")
                exit(1)

        constraintsEnum += 'num\n};\n'

        constraintsArray = constraintsArray[: -2]
        constraintsArray += '};\n'

        for con_num, macro_name, var_name, cor_cons in [
            (load_cons_num, 'LoadRelatedCons', 'loadRelatedCons', loadRelatedCons),
            (time_cons_num, 'TimeRelatedCons', 'timeRelatedCons', timeRelatedCons),
            (range_cons_num, 'RangeRelatedCons', 'rangeRelatedCons', rangeRelatedCons)]:
            if con_num:
                content += '#define ' + macro_name + '\nconst Constraint ' + var_name + '[' + str(
                    con_num) + '] = {' + cor_cons
                content = content[: -2]
                content += '};\n'

        f.write('#ifndef BASICHEADERSOFROUTESRELATEDPROBLEMS_CUSTOM_HEADER_H\n' +
                '#define BASICHEADERSOFROUTESRELATEDPROBLEMS_CUSTOM_HEADER_H\n' +
                constraintsEnum + constraintsArray + content +
                '#endif')
